package com.epoint.mobileoa.tools.dialog;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.tools.PhoneHelp;

import android.app.Dialog;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author liyc
 * @time 2012-10-9 上午8:21:31
 * @annotation 移动办公自定义对话框
 */
public class SuperDialog extends Dialog{

	private Button btPos,btNeg;
	private TextView tvMsg,tvTitle;
	private ImageView iv;
	public SuperDialog(Context con)
	{
		super(con,R.style.superdialog);
		LayoutInflater mInflater = LayoutInflater
				.from(con);
		View view = mInflater.inflate(R.layout.superdialog, null);
		btPos = (Button)view.findViewById(R.id.btPos);
		btNeg = (Button)view.findViewById(R.id.btNeg);
		tvMsg = (TextView) view.findViewById(R.id.tvMsg);
		tvTitle = (TextView) view.findViewById(R.id.tvTitle);
		iv = (ImageView) view.findViewById(R.id.ivIcon);
		setContentView(view);
		Window dialogWindow = this.getWindow();        
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = PhoneHelp.getPhoneWidth(con)-20;
//		lp.alpha = 0.9f; // 透明度
		getWindow().setAttributes(lp);
		//模糊
		//Window win = this.getWindow();
		//win.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, 
		//WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
	}

	public SuperDialog setPositiveButton(String text, View.OnClickListener listener)
	{
		btPos.setText(text);
		btPos.setVisibility(View.VISIBLE);
		if(listener!=null){
			btPos.setOnClickListener(listener);
		}
		else
		{
			btPos.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					dismiss();
				}
			});
		}
		return this;
	}

	public SuperDialog setNegativeButton(String text, View.OnClickListener listener)
	{
		btNeg.setText(text);
		btNeg.setVisibility(View.VISIBLE);
		if(listener!=null){
			btNeg.setOnClickListener(listener);
		}
		else
		{
			btNeg.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					dismiss();
				}
			});
		}
		return this;
	}

	public SuperDialog setMessage(String msg)
	{
		tvMsg.setText(Html.fromHtml(msg));
		return this;
	}

	public SuperDialog setTitle_Epoint(String title)
	{
		tvTitle.setText(title);
		return this;
	}

	public SuperDialog setIcon(int icon)
	{
		iv.setBackgroundResource(icon);
		return this;
	}
}
